<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>Social Mobile</title>
<script>
var chkNative = true;
</script>
<!-- jQuery and jQuery Mobile -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script	src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

<link rel="stylesheet" href="css/mobile-style.css" />
<script type="text/javascript" src="js/social-mobile.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>

</head>
<body>

	<!-- Home -->
	<div data-theme="a" data-role="page" id="login-mobile-page">
		<div data-role="content">

			<center>
			<img alt="" src="img/logossw.png">
			<br>
			<img src="img/txtssw.png">
			<form id="frm-login" action="/social-mobile-web/rest/profile/login"  data-ajax="false">
				<div data-role="fieldcontain">
					<label for="dsLogin"> Usuário </label> <br/> <input name="dsLogin"
						id="dsLogin" placeholder="" value="" type="text">
				</div>
				<div data-role="fieldcontain">
					<label for="dsPassword"> Senha </label> <br/> <input name="dsPassword"
						id="dsPassword" placeholder="" value="" type="password">
				</div>

				<input id="login-submit" type="submit" value="Conectar">
				
				<br><a href="javascript:resetpwd();">Reiniciar Senha</a><br>
			</form>
			
			<div id="msg-display"></div>
		</div>
		<!--div data-position="fixed" -->
			<center><i>Para maior segurança e privacidade, apenas usuários convidados terão acesso ao aplicativo.</i> <br>
			Se você possui um perfil no site CRS ou Sexlog, envie-nos um email. <br>
			<a href="mailto:sswbrmobile@gmail.com">sswbrmobile@gmail.com</a></center>
		<!--/div -->
	</div>


<script>
function resetpwd() {
	showLoadingMsg();
	  /* get some values from elements on the page: */
	  var $form = $("#frm-login"),
	      login = $form.find( 'input[name="dsLogin"]' ).val(),
	      url = "/social-mobile-web/rest/profile/reset";
	 
	  /* Send the data using post */
	  var posting = $.post( url, { 'dsLogin': login } );
	 
	  /* Put the results in a div */
	  posting.done(function( data ) {
		if (data == "sucess") {
			//location.href = "login.html";
			hideLoadingMsg();
			$("#msg-display").html("Um email com a nova senha foi enviado.");
		} else {
			hideLoadingMsg();
			$("#msg-display").html(data);
		}
	    
	  });
}

/* attach a submit handler to the form */
$("#frm-login").submit(function(event) {

	showLoadingMsg();

	/* stop form from submitting normally */
  event.preventDefault();
 
  /* get some values from elements on the page: */
  var $form = $( this ),
      login = $form.find( 'input[name="dsLogin"]' ).val(),
      pwd = $form.find( 'input[name="dsPassword"]' ).val(),
      url = $form.attr( 'action' );
 
  /* Send the data using post */
  var posting = $.post( url, { 'dsLogin': login, 'dsPassword': pwd } );
 
  /* Put the results in a div */
  posting.done(function( data ) {
	if (data == "sucess") {
		$.cookie("login", login, {expires: new Date(2020, 01, 31, 11, 00, 00)});
		$.cookie("pwd", pwd, {expires: new Date(2020, 01, 31, 11, 00, 00)});
		
		location.href = "users.html"
	} else {
		hideLoadingMsg();
		$("#msg-display").html(data);
	}
    
  });
});

</script>
</body>
</html>
